package com.wangrui.controller;


import com.wangrui.pojo.School;
import com.wangrui.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王锐
 * @since 2020-07-05
 */
@Controller
@RequestMapping("/school")
public class SchoolController {

    @Autowired
    private SchoolService schoolService;

    @RequestMapping(value = "/queryAll")
    public ResponseEntity<List<School>> queryAll() {
        List<School> listSchool = schoolService.queryAllSchool();
        return  ResponseEntity.ok(listSchool);
    }

    @RequestMapping("/schoolList")
    public String schoolListHtml()  {
        return "school/schoolList";
    }
    @RequestMapping("/save")
    public String saveHtml()  {
        return "school/save";
    }
    @RequestMapping("/update")
    public String updateHtml()  {
        return "school/update";
    }

    @RequestMapping("/QueryAllSchools")
    public ResponseEntity<Map<String, Object>> QueryAllSchools(
            @RequestParam("page")int start,
            @RequestParam("rows")int end
    ) {
        Map<String, Object> stringObjectMap = schoolService.Allschools(start, end);
        return ResponseEntity.ok(stringObjectMap);
    }

    @RequestMapping("/schoolSave")
    public ResponseEntity<Void> schoolSave(School school)  {
        schoolService.schoolSave(school);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/schoolUpdate")
    public ResponseEntity<Void> schoolUpdate(School school)  {
        schoolService.schoolUpdate(school);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/schoolDelete")
    @ResponseBody
    public String schoolDelete(int  ids)  {
        schoolService.schoolDelete(ids);
        return "ok";
    }


}

